package com.github.binarywang.demo.wx.mp.handler;

import cn.xsshome.taip.nlp.TAipNlp;
import cn.xsshome.taip.ocr.TAipOcr;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
public class MenuHandler extends AbstractHandler {
    @Value("${wx.ai.AIID}")
    String AIID ;
    @Value("${wx.ai.AIKey}")
    String AIKey;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService weixinService,
                                    WxSessionManager sessionManager) {
        this.logger.info("\n-----------------进入MenuHandler处理器-----------------");



        //type:event, event:pic_weixin, key:rselfmenu_2_1
        String msg = String.format("type:%s, event:%s, key:%s",
            wxMessage.getMsgType(), wxMessage.getEvent(),
            wxMessage.getEventKey());
        this.logger.info("\n-----------------msg---------"+msg);
        if (MenuButtonType.VIEW.equals(wxMessage.getEvent())) {
            return null;
        }
        if (MenuButtonType.PIC_WEIXIN.equals(wxMessage.getEvent())) {
            this.logger.info("\n收到微信推送的PIC_WEIXIN事件");

            return null;
        }


        return WxMpXmlOutMessage.TEXT().content(msg)
            .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
            .build();
    }

}
